<template>
  <div class="MyBox">
    <div class="head">
      <img :src="getUser().avatarImgIdStr" alt="" />
      <div class="headbox1">
        <h2>{{ getUser()?.userName }}</h2>
        <div class="headbox2">
          {{ userDital.follows }}<span>关注</span> {{ userDital.followeds
          }}<span>粉丝</span> {{ userDital.authority }}<span>获赞</span>
        </div>
        <div class="headbox3">{{ getAge(userDital.birthday) }}岁</div>
      </div>
    </div>
    <div class="contenyBox">
      <div class="header">创建的歌单</div>
      <div class="box">
        <div class="item" v-for="(item, index) in userSongSheetList" :key="index" @click="
          goToPages('/home/userSongSheet', { id: item.id, name: item.name })
          ">
          <div class="lbox">
            <img :src="item.coverImgUrl" alt="" />
          </div>
          <div class="lfont">{{ item.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, toRefs, ref } from "vue";
import { getUser } from "@/utils/auth";
import useCounterStore from "@/stores/counter";
import { getUserList } from "@/api/user";
import { useRouter } from "vue-router";
const { userSongSheetList, userSongSheetId, userSongSheetName } = toRefs(
  useCounterStore()
);
const router = useRouter();
const userDital = ref();

onMounted(async () => {
  const { data } = await getUserList({ uid: getUser().userId });
  userDital.value = data.profile;
});


function goToPages(url: string, obj = {} as { id: number; name: string }) {
  if (obj.id) {
    // 设置歌曲表id
    userSongSheetId.value = obj.id;
    // 设置歌曲表名
    userSongSheetName.value = obj.name;
  }
  router.push(url);
}
function getAge(birthday: string) {
  //出生时间 毫秒
  var birthDayTime = new Date(birthday).getTime();
  //当前时间 毫秒
  var nowTime = new Date().getTime();
  //一年毫秒数(365 * 86400000 = 31536000000)
  return Math.ceil((nowTime - birthDayTime) / 31536000000);
}
</script>

<style lang="scss" scoped>
.MyBox::-webkit-scrollbar {
  display: none;
}

.MyBox {
  color: white;
  padding: 1vw 2vw;
  box-sizing: border-box;
  overflow-y: scroll;
  max-height: 85vh;

  .head {
    width: 100%;
    margin-top: 6vw;
    display: flex;

    img {
      width: 8vw;
      height: 8vw;
      border-radius: 50%;
      margin: 1vw;
    }

    .headbox1 {
      margin-left: 1vw;
      font-size: 1.2vw;

      h2 {
        font-weight: normal;
        padding: 0.5vw 0;
      }

      .headbox2 {
        color: #d7d7d7;
        margin-bottom: 1vw;

        span {
          color: #c4c4c4;
          margin: 0 0.5vw;
        }
      }

      .headbox3 {
        background: #2a2a2a;
        color: #bbbbbb;
        width: 4vw;
        height: 2vw;
        text-align: center;
        line-height: 2vw;
        font-size: 1.2vw;
      }
    }
  }

  .contenyBox {
    width: 80vw;
    margin-top: 1vw;

    .header {
      color: #808080;
      padding: 1vw 0;
    }

    .box {
      width: 100%;
      .like,
      .item {
        display: inline-block;
        width: 13vw;
        height: 16vw;
        margin-right: 2vw;
        img {
          width: 100%;
          height: 100%;
          border-radius: 0.5vw;
        }

        .lbox {
          width: 13vw;
          height: 13vw;
          border-radius: 0.5vw;
        }

        .lfont {
          width: 13vw;
          height: 3vw;
          line-height: 3vw;
          color: #d1d1d1;
          font-size: 1.2vw;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
        }
      }
    }
  }
}
</style>